<!--[if !IE]> -->
<script type="text/javascript">
	window.jQuery || document.write("<script src='/assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
</script>
<!-- <![endif]-->
<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='/assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->
<script type="text/javascript">
	if("ontouchend" in document) document.write("<script src='/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/typeahead-bs2.min.js"></script>
<!-- page specific plugin scripts -->
<script src="/assets/js/jquery.dataTables.js"></script>
<script src="/assets/js/jquery.dataTables.bootstrap.js"></script>
<script type="text/javascript" src="http://cdn.datatables.net/plug-ins/28e7751dbec/integration/bootstrap/3/dataTables.bootstrap.js"></script>

<!-- ace scripts -->
<script src="/assets/js/ace-elements.min.js"></script>
<script src="/assets/js/ace.min.js"></script>
<script src="/assets/js/chosen.jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/jquery.serializejson.min.js"></script>
<script type="text/javascript" src="/assets/js/jquery-extends.js"></script>
<script type="text/javascript" src="/assets/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="/assets/js/validate_add_method.js"></script>
<script type="text/javascript" src="/assets/js/jquery.cookie.js"></script>
<script type="text/javascript" src="/assets/js/menu.js"></script>
<script src="/assets/js/layer/layer.js" type="text/javascript"></script>
<script src="/assets/js/layer/layer.js" type="text/javascript"></script>
<script>
$(function(){
	  // 匹配qq      
    jQuery.validator.addMethod("pwdEq", function(value, element) {    
         return  this.optional(element)||value==$("#updatePwdForm input[name='oneNewPwd']").val();       
    }, "两次密码输入不一致");   
	$.ajaxSetup({
		cache: false,
	  	complete: function (xhr, status) 
	  	{ 
	  	 	var sessionstatus=xhr.getResponseHeader("sessionstatus"); //通过XMLHttpRequest取得响应头，sessionstatus，   
	  		if(sessionstatus=="timeout"){
	  			  window.location.href="/";
	  			  return;
	  		}
	  		var permissionValid = xhr.getResponseHeader("permission");
	  		if(permissionValid=="notValid"){
	  			  window.location.href=$("#ctx").val()+"/error-500.html";
	  			  return;
	  		}
	  		var authJSONStr = eval("(" +$.cookie("auth_url") + ")");
	  		var authJSON = eval("("+authJSONStr+")");
	  		var $but = $("a[type='button'][authCode],button[authCode]").hide();
	  		for(var i=0;i<$but.length;i++){
	  			for(var j=0;authJSON!=null&&j<authJSON.length;j++){
		  			var $butEle = $but.eq(i);
		  			var auth = authJSON[j];
		  			if(auth.id!=null&&$butEle.attr("authCode")==auth.id){
		  				$butEle.show();
		  			  }
		  			}
	  		}
	  	}
	  });
	$("#updatePwdForm").validate();
	$("#updatePwdBtn").click(function(){
		$("#updatePwd_dialog").modal();
	});
	 $("#updatePwd_dialog").on("hidden.bs.modal", function() {
         $(this).removeData("bs.modal");
         validate.resetForm();
     });
	$("#updatePwdSubmitBtn").click(function(){
		if(!$("#updatePwdForm").valid()){
			return ;
		}
		$.ajax({
                 type: "post",
                 url: "system/updatePwd",
                 data: $("#updatePwdForm").serializeJSON(),
                 dataType: "json",
                 success: function(data){
                 	if(data.code==0){
                 		$("#updatePwd_dialog").modal("hide");
                 	}else{
                 		alert(data.message);
                 	}
                 }
         	});
	})
	
})
function limitStr(str,len){
	if(getByteLen(str)<=len+3){
		return str;
	}else{
		return getByteVal(str,len)+"...";
	}
}
function getByteLen(val) { 
	var len = 0; 
	for (var i = 0; i < val.length; i++) { 
	if (val[i].match(/[^\x00-\xff]/ig) != null) //全角 
	   len += 2; 
	else 
	  len += 1; 
	} 
	return len; 
}
//返回val在规定字节长度max内的值 
function getByteVal(val, max) { 
		var returnValue = ''; 
		var byteValLen = 0; 
		for (var i = 0; i < val.length; i++) { 
			if (val[i].match(/[^\x00-\xff]/ig) != null) 
				byteValLen += 2; 
			else 
				byteValLen += 1; 
			if (byteValLen > max) 
				break; 
			returnValue += val[i]; 
		} 
	return returnValue; 
} 
</script>